home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_edit.arc / ED11.A < prev    next >
Text File  |  1991-09-08  |  11KB  |  537 lines

  1. ;    ED11.A    --    Screen and keyboard interface routines for the PC
  2. ;
  3. ;    This is a modified version of the PCIO.A routines included with the
  4. ;        C ware (Desmet) C compiler and included with permission of
  5. ;        C ware
  6. ;
  7.  
  8.         dseg
  9. ;
  10. ;    CHARACTER ATTRIBUTE EQUATES
  11. ;
  12. NORMAL    EQU    7
  13. REVERSE    EQU    112
  14. BLINK    EQU    128
  15. INTENSE    EQU    8
  16. ;
  17. ;    ATTRIBUTE SET CODES
  18. ;
  19. SETNORMAL    EQU    0
  20. SETREVERSE    EQU    1
  21. SETINTENSE    EQU    2
  22. SETFAINT    EQU    3
  23. SETBLINK    EQU    4
  24. NOBLINK        EQU    5
  25. ;
  26.  
  27. ;/* control key translations */
  28. UP1    EQU    10
  29. DOWN1    EQU    13
  30. UP2    EQU    21
  31. DOWN2    EQU    4
  32. LEFT1    EQU    25
  33. RIGHT1    EQU    18
  34. INS1    EQU    14
  35. EDIT1    EQU    5
  36. ESC1    EQU    27
  37. DEL1    EQU    127
  38. ZAP1    EQU    26
  39. ABT1    EQU    24
  40. SPLT1    EQU    19
  41. JOIN1    EQU    16
  42. DTOCH    EQU    1
  43. GTOCH    EQU    2
  44. HOME    EQU    6
  45. DSCROL     EQU    7
  46. GOTO    EQU    17
  47. LSTRT    EQU    11
  48. LEND    EQU    12
  49. USCROL    EQU    15
  50. ERASE    EQU    20
  51. LFTDEL    EQU    8
  52. BEGINPL    EQU    200
  53. ENDPL    EQU    201
  54. PUTIT    EQU    202
  55. PICKIT    EQU    203
  56. RECORD    EQU    204
  57. REPLAY    EQU    205
  58. ABSLEFT    EQU    206
  59. ABSRGHT    EQU    207
  60. PAGEUP    EQU    208
  61. PAGEDN    EQU    209
  62.  
  63. ;    the table that is used to make the translation
  64.  
  65. convert:
  66.         db    72, UP2            ;up_char
  67.         db    80, DOWN2        ;down_char
  68.         db    75, LEFT1        ;left_char
  69.         db    77, RIGHT1        ;right_char
  70.         db    71, HOME        ;home
  71.         db    79, DEL1         ;end
  72.         db    73, USCROL        ;pageup_char
  73.         db    81, DSCROL        ;pagedown_char
  74.         db    82, UP1            ;Ins_char
  75.         db    83, ZAP1        ;Del_char
  76.         db    115, LSTRT        ;ctl-left
  77.         db    116, LEND        ;ctl-rgt
  78.         db    59, ESC1        ;F1
  79.         db    60, EDIT1        ;F2
  80.         db    61, GOTO        ;F3
  81.         db    62, INS1        ;F4
  82.         db    63, ERASE        ;F5
  83.         db    64, ABT1        ;F6
  84.         db    65, BEGINPL        ;F7
  85.         db    66, ENDPL        ;F8
  86.         db    67, PICKIT        ;F9
  87.         db    68, PUTIT        ;F10
  88.         db    120,SPLT1        ;alt-1
  89.         db    121,JOIN1        ;alt-2
  90.         db    122,DTOCH        ;alt-3
  91.         db    123,GTOCH        ;alt-4
  92.         db    130,ABSLEFT        ;alt -
  93.         db    131,ABSRGHT        ;alt +
  94.         db    132,PAGEUP        ;ctl-Pg Up
  95.         db    118,PAGEDN        ;ctl-Pg Dn
  96.         db    0, 255 ; illegal character
  97.  
  98. ;    equates for bios interface.
  99.  
  100. ;    the interrupt and codes for the screen interface interrupt.
  101.  
  102. video        equ    10h        ;interrupt for dealing with screen
  103.  
  104. mode        equ    0        ;code for setting new screen mode
  105. curtype        equ    1        ;code for setting new cursor type
  106. setcur        equ    2        ;code for addressing cursor
  107. readcur        equ    3        ;code for reading cursor location
  108. readlp        equ    4        ;code for reading light pen position
  109. setpage        equ    5        ;code to select active page
  110. scrollup    equ    6        ;code to scroll screen up
  111. scrolldn    equ    7        ;code to scroll screen nown
  112. readch        equ    8        ;code to read a character from screen
  113. writeach    equ    9        ;code to write char and attributes
  114. writech        equ    10        ;code to write character only
  115. setpal        equ    11        ;code to set new setpal or border
  116. wdot        equ    12        ;code to write a dot
  117. rdot        equ    13        ;code to read a dot
  118. wtty        equ    14        ;code to write as if teletype
  119. state        equ    15        ;code to find current screen status
  120.  
  121.  
  122.  
  123. ;    the interrupt and codes for the keyboard interface.
  124.  
  125. keyboard    equ    16h        ;interrupt 16 to deal with keyboard
  126.  
  127. cicode        equ    0        ;code for reading a character
  128. cstscode    equ    1        ;code for keyboard status
  129.  
  130.  
  131.  
  132.  
  133. ;    caution: must change column number if 40 column mode
  134.  
  135. crt_cols    equ    80
  136.  
  137. ;    variables available to a C88 program
  138.  
  139.         public    scr_cols_, scr_rows_
  140.         public    scr_mode_,scr_page_,scr_attr_
  141.  
  142. scr_cols_:    dw    crt_cols    ;current number of columns
  143. scr_rows_:    dw    25        ;current number of rows
  144. scr_mode_    db    0        ;current screen mode
  145. scr_page_    db    0        ;current page
  146. scr_attr_    db    NORMAL        ;current attributes for screen
  147.                     ;NORMAL is white letters on black
  148.  
  149.  
  150.  
  151.         cseg
  152.  
  153. ;    SCR_SETUP_    scr_setup must be called before any use of any
  154. ;            other routine unless the starting mode is 80X25
  155. ;            character mode (3,4 or 7).
  156.  
  157. ;            Usage:    scr_setup();
  158.  
  159.         public    scr_setup_
  160. scr_setup_:    push    bp
  161.         mov    ah,state        ;get current state
  162.         int    video
  163.         mov    scr_mode_,al        ;current mode
  164.         mov    cl,ah            ;make cols a word
  165.         mov    ch,0
  166.         mov    scr_cols_,cx        ;40 or 80 columns
  167.         mov    scr_page_,bh
  168.         mov    scr_attr_,NORMAL        ;set to white chars on black
  169.         cmp    al,4            ;see if a character mode
  170.         jc    got_attr
  171.         cmp    al,7            ;7 is for graphics mode
  172.         jz    got_attr
  173.         mov    scr_attr_,0        ;attribute is zero in graphics
  174. got_attr:    mov    ah,0            ;return int containing mode
  175.         pop    bp
  176.         ret
  177.  
  178.  
  179.  
  180. ;    SCR_SETMODE_        set a new screen mode
  181.  
  182. ;                Usage:    scr_setmode(new mode);
  183.  
  184.         public    scr_setmode_
  185. scr_setmode_:    push    bp
  186.         mov    bp,sp
  187.         mov    al,[bp+4]    ; new mode value
  188.         mov    ah,mode
  189.         int    video        ; set new mode
  190.         call    scr_setup_    ;remember new values
  191.         pop    bp
  192.         ret
  193.  
  194.  
  195. ;    SCR_ROWCOL_        sets cursor at any location.
  196.  
  197. ;                Usage:    scr_rowcol(new row, new column);
  198.  
  199.         public    scr_rowcol_
  200. scr_rowcol_:                ; move cursor to x,y
  201.         push    bp        ; save from bios
  202.         mov    bp,sp
  203.         mov    dx,[bp+6]    ; column
  204.         mov    ax,[bp+4]    ; row
  205.         mov    dh,al
  206.         mov    bh,scr_page_    ; force page zero
  207.         mov    ah,setcur    ; set cursor location
  208.         int    video        ; call bios
  209.         pop    bp
  210.         ret
  211.  
  212.  
  213.  
  214. ;    SCR_CLR_        clear entire screen
  215.  
  216. ;                Usage:    scr_clr();
  217.  
  218.         public    scr_clr_
  219. scr_clr_:                ; clear screen
  220.  
  221.  
  222.         push    bp        ;save from video call
  223.         mov    al,0        ;ask for a clear window
  224.         xor    cx,cx        ;start at 0,0
  225.         mov    dh,24        ;24 is the last line
  226.         mov    dl,byte scr_cols_    ;clear entire width
  227.         dec    dl        ;last column is width-1
  228.         mov    bh,scr_attr_    ;attributes for new blanks
  229.         mov    ah,scrollup    ;ask for a scrollup to clear
  230.         int    video        ;do the clear
  231.         pop    bp
  232.         ret
  233.  
  234.  
  235.  
  236. ;    SCR_CLRL_        clear rest of line.
  237.  
  238. ;                Usage:        scr_clrl();
  239.  
  240.         public    scr_clrl_        
  241. scr_clrl_:                ; clear rest of line
  242.         push    bp
  243.         mov    ah,readcur    ;see where we are
  244.         int    video
  245.         mov    cl,byte scr_cols_    ;calc how many chars left in line
  246.         sub    cl,dl        ;number left
  247.         mov    ch,0        ;number of blanks needed
  248.         mov    al,' '        ;write blanks
  249.         mov    bl,scr_attr_    ;normal attributes
  250.         mov    ah,writeach    ;write the blanks
  251.         int    video
  252.         pop    bp
  253.         ret
  254.  
  255.  
  256.  
  257.  
  258.  
  259. ;    SCR_SCUP_        scroll text up leaving top line alone.
  260.  
  261. ;                Usage:    scr_scup();
  262.  
  263.         public    scr_scup_
  264. scr_scup_:            ; scroll last line, screen from line 2 to 24
  265.         mov    ax,scr_cols_    ;need last column of screen
  266.         dec    ax
  267.         push    ax
  268.         mov    ax,24        ;scroll through last line
  269.         push    ax
  270.         xor    ax,ax        ;from column 0
  271.         push    ax
  272.         inc    ax        ;leave top line alone
  273.         push    ax
  274.         push    ax        ;scroll by 1
  275.         call    scr_scrup_    ;do the scroll
  276.         add    sp,10        ;clear arge
  277.         ret
  278.  
  279.  
  280. ;    SCR_SCDN_        scroll all but the top line down one.
  281.  
  282. ;                Usage:    scr_scdn();
  283.  
  284.         public    scr_scdn_
  285. scr_scdn_:
  286.         mov    ax,scr_cols_    ;need last column of screen
  287.         dec    ax
  288.         push    ax
  289.         mov    ax,24        ;scroll through last line
  290.         push    ax
  291.         xor    ax,ax        ;from column 0
  292.         push    ax
  293.         inc    ax        ;leave top line alone
  294.         push    ax
  295.         push    ax        ;scroll by 1
  296.         call    scr_scrdn_    ;do the scroll
  297.         add    sp,10        ;clear arge
  298.         ret
  299.  
  300.         push    ax
  301.         xor    ax,ax        ;from column 0
  302.         push    ax
  303.         inc    ax        ;leave top line alone
  304.         push    ax
  305.         push    ax        ;scroll by 1
  306.         call    scr_scrup_    ;do the scroll
  307.         add    sp,10        ;clear arge
  308.         ret
  309.  
  310. ;    SCR_SCRUP_        Scroll the screen up. The window is scrolled
  311. ;                up nline lines. A zero nline will clear the
  312. ;                window. Top left of the screen in 0,0.
  313.  
  314. ;            Usage: scr_scrup(nline,fromrow,fromcol,torow,tocol);
  315.  
  316.         public    scr_scrup_
  317. scr_scrup_:    push    bp
  318.         mov    bp,sp
  319.         mov    al,[bp+4]    ;number of lines
  320.         mov    ch,[bp+6]    ;starting row
  321.         mov    cl,[bp+8]    ;starting column
  322.         mov    dh,[bp+10]    ;ending row
  323.         mov    dl,[bp+12]    ;ending column
  324.         mov    bh,scr_attr_    ;current attribute
  325.         mov    ah,scrollup
  326.         int    video        ;do the scroll
  327.         pop    bp
  328.         ret
  329.  
  330.  
  331.  
  332. ;    SCR_SCRDN_        scroll the screen down. the window is scrolled
  333. ;                down nline lines. A zero nline will clear the
  334. ;                window. Top left of the screen in 0,0.
  335.  
  336. ;            Usage: scr_scrdn(nline,fromrow,fromcol,torow,tocol);
  337.  
  338.         public    scr_scrdn_
  339. scr_scrdn_:    push    bp
  340.         mov    bp,sp
  341.         mov    al,[bp+4]    ;number of lines
  342.         mov    ch,[bp+6]    ;starting row
  343.         mov    cl,[bp+8]    ;starting column
  344.         mov    dh,[bp+10]    ;ending row
  345.         mov    dl,[bp+12]    ;ending column
  346.         mov    bh,scr_attr_    ;current attribute
  347.         mov    ah,scrolldn
  348.         int    video        ;do the scroll
  349.         pop    bp
  350.         ret
  351.  
  352.  
  353.  
  354. ;    SCR_CO_            write a character to the screen. this
  355. ;                routine increments the cursor position
  356. ;                after writing. normal C88 puts and printf
  357. ;                statements can also be used to write to the
  358. ;                screen.
  359.  
  360. ;                Usage:    scr_co_(character);
  361.  
  362.         public    scr_co_
  363. scr_co_:                    ; standard console output
  364.         push    bp
  365.         mov    bp,sp
  366.         mov    al,[bp+4]    ;character to write
  367.         push    ax
  368.         push    ax
  369.         mov    bh,scr_page_
  370.         mov    ah,readcur
  371.         int    video
  372.         cmp    dl,crt_cols-1
  373.         jle    u20
  374.         mov    dl,crt_cols-1    
  375. u20:    pop    ax
  376.         cmp    al,8
  377.         je    u8
  378.         cmp    al,0dh
  379.         je    u9
  380.         cmp    al,0ah
  381.         je    u10
  382.         cmp    al,07h
  383.         je    u11
  384.         mov    bh,scr_page_
  385.         mov    bl,scr_attr_
  386.         mov    ah,writeach        ;use write char/attr routine
  387.         mov    cx,1
  388.         int video
  389.         inc    dl
  390.         cmp    dl,crt_cols
  391.         jnz    u7
  392.         dec    dl
  393.         jmp    u7
  394.  
  395. ;        mov    dl,0
  396. ;        cmp    dh,24
  397. ;        jnz    u6
  398.  
  399. u1:        mov    ah,setcur
  400.         mov    bh,0
  401.         int    video
  402.         mov    bh,scr_attr_
  403. u3:        mov    ax,0601h
  404.         mov    cx,0
  405.         mov    dh,24
  406.         mov    dl,crt_cols
  407.         dec    dl
  408. u4:        int    video
  409. u5:        pop    ax        
  410.         pop    bp
  411.         ret
  412. u6:        inc    dh
  413. u7:        mov    ah,setcur
  414.         jmp    u4
  415. u8:        cmp    dl,0
  416.         je    u7
  417.         dec    dl
  418.         jmp    u7
  419. u9:        mov    dl,0
  420.         jmp    u7
  421. u10:    cmp    dh,24
  422.         jne    u6
  423.         jmp    u1
  424. u11:    jmp    u5        
  425. ;
  426. ;    SCR_CHR_ATTR_    set screen attribute
  427. ;
  428. ;                Usage:  scr_chr_attr_(character);
  429. ;
  430.         public    scr_chr_attr_
  431. scr_chr_attr_:
  432.         push    bp
  433.         mov    bp,sp
  434.         mov    al,[bp+4]    ;attribute
  435.         cmp    al,SETNORMAL
  436.         je    norset
  437.         cmp    al,SETREVERSE
  438.         je    revset
  439.         cmp    al,SETBLINK
  440.         je    blnkset
  441.         cmp    al,SETINTENSE
  442.         je    intset
  443.         cmp    al,SETFAINT
  444.         je    fntset
  445.         cmp    al,NOBLINK
  446.         je    blnkres
  447. attfin:    
  448.         pop    bp
  449.         ret
  450. norset:    mov    al,scr_attr_
  451.         and    al,136    ;save intensity and blink state
  452.         or    al,NORMAL
  453.         mov    scr_attr_,al
  454.         jmp    attfin
  455. revset:    mov    al,scr_attr_
  456.         and    al,136
  457.         or    al,REVERSE
  458.         mov    scr_attr_,al
  459.         jmp attfin
  460. blnkset:mov    al,scr_attr_
  461.         and    al,INTENSE
  462.         or    al,NORMAL
  463.         or    al,BLINK
  464.         mov    scr_attr_,al
  465.         jmp    attfin
  466. blnkres:mov    al,scr_attr_
  467.         and    al,INTENSE
  468.         or    al,NORMAL
  469.         mov    scr_attr_,al
  470.         jmp    attfin
  471. intset:    mov    al,scr_attr_
  472.         or    al,INTENSE
  473.         mov    scr_attr_,al
  474.         jmp    attfin
  475. fntset: mov    al,scr_attr_
  476.         and    al,247
  477.         mov    scr_attr_,al
  478.         jmp    attfin
  479.  
  480.  
  481. ;    SCR_CI_            keyboard input. function and soft keys are
  482. ;                translated. see equates for values.
  483.  
  484. ;                Usage:    character = scr_ci();
  485.  
  486.         public    scr_ci_
  487. scr_ci_:                ;return the next character
  488.                     ; translate if necessary
  489.         push    bp
  490.         mov    ah,cicode    ;ask for a keyboard character
  491.         int    keyboard
  492.         CMP    AH,74
  493.         JE    PLUS_KEY  
  494.         CMP    AH,78
  495.         JE    MINUS_KEY 
  496.         cmp    al,0
  497.         jne    not_special
  498.         mov    bx, offset convert    ; convert special key
  499. ci_loop:
  500.         cmp    byte[bx],0
  501.         jz    got_it
  502.         cmp    ah, byte[bx]
  503.         je    got_it
  504.         add    bx,2
  505.         jmp    ci_loop
  506. got_it:        inc    bx
  507.         mov    al,[bx]
  508.         mov    ah,0
  509.         pop    bp
  510.         ret
  511. not_special:    mov    ah,0
  512.         pop    bp
  513.         ret
  514.  
  515. PLUS_KEY:    MOV    AL,RECORD
  516.         JMP    not_special
  517. MINUS_KEY:    MOV    AL,REPLAY
  518.         JMP    not_special
  519.     
  520.  
  521.  
  522. ;    SCR_CSTS_        return character if any available. otherwise
  523. ;                return zero.
  524.  
  525. ;                Usage:    character = scr_csts();
  526.  
  527.         public    scr_csts_
  528. scr_csts_:                ;return coded character if any available
  529.         push    bp
  530.         mov    ah,cstscode
  531.         int    keyboard
  532.         mov    ax,0
  533.         jz    csts_over
  534.         call    scr_ci_        ;get the coded character
  535. csts_over:    pop    bp
  536.         ret
  537.